<?php

// 获取项目汇选列表
// GET project.volist

namespace app\api\resource\project;
use think\Db;
use app\api\lib\Page;

class Volist
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = [];
    // 描述
    public $_description = '获取项目汇选列表';
    // 参数
    public $_param  = [
        'skey'     => '检索关键词',
        'round'    => '融资轮次',
        'industry' => '所属行业',
        'city'     => '所在城市',
    ];
    // 返回
    public $_return = [
        200 => '获取成功',
    ];

    public function run(&$request)
    {
        $page  = $request->get('page/d',1,'abs');
        $show  = $request->get('show/d',10,'abs');

        $skey     = $request->get('skey/s','','trim');
        $round    = $request->get('round/s','','trim');
        $industry = $request->get('industry/s','','trim');
        $city     = $request->get('city/s','','trim');

        if ( !empty($skey) ) {
            $where['title|words'] = ['like','%' . $skey . '%'];
        } else {
            if ( !empty($round) )    $where['round']    = ['like','%' . $round . '%'];
            if ( !empty($industry) ) $where['industry'] = ['like','%' . $industry . '%'];
            if ( !empty($city) )     $where['city']     = ['like','%' . $city . '%'];
        }

        $table = 'project';
        $where['is_cp']   = 1;
        $where['delete_time'] = ['eq',0];
        $list = Db::name($table)->where($where)->order('id desc')->page($page,$show)->select();

        $pagelist = Page::run($table, $page, $show, $where, $list);

        return [200,$pagelist];
    }
}